<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="lib/vue.js"></script>
    <style>
        .ball {
            width: 15px;
            height: 15px;
            border-radius: 50%;
            background-color: red;
        }
    </style>
</head>

<body>
    <div id="app">
        <input type="button" value="快到碗里来" @click="flag=!flag">
        <transition @before-enter="beforeEnter" @enter="enter" @after-enter="afterEnter">
            <div class="ball" v-show="flag"></div>
        </transition>
    </div>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                flag: false
            },
            methods: {
                //动画钩子函数的第一个参数 el 表示要执行动画的dom元素 是个原生的js dom对象
                beforeEnter(el) {
                    //动画开始之前 动画尚未开始 可设置动画起始位置和样式
                    el.style.transform = "translate(0,0)"
                },
                //要让动画完成之后 立即执行afterEnter 参数加done 并调用done()
                enter(el, done) {
                    el.offsetWidth
                    el.style.transform = "translate(150px,450px)"
                    el.style.transition = 'all 1s ease'
                    done()
                },
                afterEnter(el) {
                    this.flag = !this.flag
                }
            }
        });
    </script>
</body>

</html>